package com.administrator.customviewtest.ipc.aidl;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.util.Log;

import com.administrator.customviewtest.IMyMessageAidl;
import com.administrator.customviewtest.R;
import com.administrator.customviewtest.bean.*;

/**
 * Created by lsp on 2017/9/22 14 30
 */

public class BookClient extends Activity {
    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            IMyMessageAidl aidl = IMyMessageAidl.Stub.asInterface(service);
            Book book = new Book();
            book.setName("lsp");
            book.setId(123);
            try {
                aidl.setBook(book);
                aidl.setName("999");
                Log.e("ssss",aidl.getName()+" "+aidl.getBook().getName()+" "+aidl.getBook().getId());
            } catch (Exception e) {
                Log.e("sssss eros",e.toString());
                e.printStackTrace();
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_client);
        Intent intent = new Intent(this,BookManagerService.class);

//        bindService(intent,serviceConnection,BIND_AUTO_CREATE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        unbindService(serviceConnection);
//        finish();
    }
}
